/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package maquinaVirtual.view;

import java.io.File;
import java.util.LinkedList;
import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import maquinaVirtual.util.GuiUtils;
import maquinaVirtual.util.ManipuladorDeArquivo;



/**
 *
 * @author H
 */
public class MaquinaVirtualView extends javax.swing.JFrame {

    public int proximaInstrucao = 0;
    public int s = -1;
    public int posicaoMemoria = 0;
    public int enderecoRetorno = 0;
    private int numeroDaLinha = 0;
    private int linhaComentario = 0;
    private List<String> rotuloJmp;
    private List<String> enderecoRotulo;

    /**
     * Creates new form maquinaVirtual
     */
    public MaquinaVirtualView() {

        initComponents();


    }

    private void populaVariaveis() {

        this.proximaInstrucao = 0;
        this.s = -1;
        this.posicaoMemoria = 0;
        this.enderecoRetorno = 0;
        this.numeroDaLinha = 0;
        this.linhaComentario = 0;
        this.rotuloJmp = new LinkedList<>();
        this.enderecoRotulo = new LinkedList<>();
        this.limparJTable();
    }

    private void abrirArquivo() {


        JFileChooser jf = new JFileChooser();
        int returnVal = jf.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {

            this.populaVariaveis();
            File arquivo = jf.getSelectedFile();
            ManipuladorDeArquivo manipulador = new ManipuladorDeArquivo(arquivo);
            String linha = manipulador.getLinha();
            while (linha != null) {

                this.inserirLinhaCodigo(linha);
                linha = manipulador.getLinha();
            }
            this.substituirRotuloPorEndereco();
        }

    }

    private void substituirRotuloPorEndereco() {

        DefaultTableModel model = (DefaultTableModel) this.tblCodigo.getModel();

        for (int i = 0; i < model.getRowCount(); i++) {

            if (model.getValueAt(i, 1).toString().trim().toUpperCase().equals("JMP")
                    || model.getValueAt(i, 1).toString().trim().toUpperCase().equals("JMPF")
                    || model.getValueAt(i, 1).toString().trim().toUpperCase().equals("CALL")) {

                String atributo = model.getValueAt(i, 2).toString().trim().toUpperCase();
                String enderecoRotuloSubstituir = "";
                for (int j = 0; j < this.rotuloJmp.size(); j++) {

                    if (this.rotuloJmp.get(j).toString().toUpperCase().trim().equals(atributo)) {
                        enderecoRotuloSubstituir = this.enderecoRotulo.get(j).toString().toUpperCase().trim();
                        break;
                    }
                }

                if (!enderecoRotuloSubstituir.equals("")) {
                    model.setValueAt(enderecoRotuloSubstituir, i, 2);
                }
            }


        }

    }

    private void inserirLinhaCodigo(String linha) {

        DefaultTableModel model = (DefaultTableModel) this.tblCodigo.getModel();
        Object[] linhaTbl = new Object[5];
        int posicaoVetor = 0;
        boolean preenchendoVariavel = false;
        boolean parseRotulo = false;

        String valor = "";
        for (int i = 0; i < linha.length(); i++) {

            char c = linha.charAt(i);

            if (i == 0) {//PREENCHER ROTULO

                if (Character.isLetterOrDigit(c)) {

                    valor += Character.toString(c);
                    preenchendoVariavel = true;
                    parseRotulo = true;
                } else {

                    linhaTbl[posicaoVetor] = numeroDaLinha;
                    numeroDaLinha++;
                    posicaoVetor = 1;
                }
            } else {

                if (preenchendoVariavel == true) {

                    if (Character.isLetterOrDigit(c)) {
                        valor += Character.toString(c);
                    } else {

                        linhaTbl[posicaoVetor] = valor;

                        if (parseRotulo == true) {

                            this.rotuloJmp.add(valor);
                            this.enderecoRotulo.add(String.valueOf(numeroDaLinha));
                            linhaTbl[posicaoVetor] = numeroDaLinha++;
                            parseRotulo = false;
                        }

                        valor = "";
                        posicaoVetor++;
                        preenchendoVariavel = false;
                    }

                } else {
                    if (Character.isLetterOrDigit(c)) {
                        valor += Character.toString(c);
                        preenchendoVariavel = true;
                    }
                }
            }
        }


        model.addRow(linhaTbl);
        this.selecionarLinhaTabela(this.tblCodigo);
        //this.tblCodigo.setModel(model);

    }

    private void executarCodigo() {

        DefaultTableModel model = (DefaultTableModel) this.tblCodigo.getModel();
        
        
        if (this.radioPassoAPasso.isSelected()) {

            if (this.tblCodigo.getRowCount() > this.proximaInstrucao) {
                
                Object instrucao = model.getValueAt(this.proximaInstrucao, 1);
                Object atributo1 = model.getValueAt(this.proximaInstrucao, 2);
                Object atributo2 = model.getValueAt(this.proximaInstrucao, 3);
                
                this.linhaComentario = this.proximaInstrucao;
                this.proximaInstrucao++;
                this.executarInstrucao(instrucao, atributo1, atributo2);
            }
        } else {

            boolean retornoExecucao;
            do {

                Object instrucao = model.getValueAt(this.proximaInstrucao, 1);
                Object atributo1 = model.getValueAt(this.proximaInstrucao, 2);
                Object atributo2 = model.getValueAt(this.proximaInstrucao, 3);
                
                this.linhaComentario = this.proximaInstrucao;
                this.proximaInstrucao++;
                retornoExecucao = this.executarInstrucao(instrucao, atributo1, atributo2);

            } while (retornoExecucao == true);

        }
    }

    private boolean executarInstrucao(Object instrucao, Object atributo1, Object atributo2) {

        DefaultTableModel memoria = (DefaultTableModel) this.tblPilha.getModel();
        String comentario = "";

        switch (instrucao.toString().trim().toUpperCase()) {

            case "LDC":

                this.s++;
                memoria.addRow(new Object[]{this.s, atributo1});
                comentario = "S:=s + 1 ; M [s]: = k";

                break;

            case "LDV":

                this.s++;
                Object valor = memoria.getValueAt(Integer.valueOf(atributo1.toString().trim()), 1);
                memoria.addRow(new Object[]{this.s, valor});
                comentario = "S:=s + 1 ; M[s]:=M[n]";

                break;

            case "ADD":
                
                int somar = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                somar += Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                memoria.setValueAt(somar, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "M[s-1]:=M[s-1] + M[s]; s:=s - 1";
                
                break;
                
            case "SUB":
                int subtrair = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                subtrair -= Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                memoria.setValueAt(subtrair, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "M[s-1]:=M[s-1] - M[s]; s:=s - 1";
                break;
            case "MULT":
                int multiplicar = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                multiplicar *= Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                memoria.setValueAt(multiplicar, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "M[s-1]:=M[s-1] * M[s]; s:=s - 1";
                break;
            case "DIVI":
                int dividir = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                dividir /= Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                memoria.setValueAt(dividir, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "M[s-1]:=M[s-1] div M[s]; s:=s -1";
                break;
            case "INV":
                int inverterSinal = -Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                memoria.setValueAt(inverterSinal, this.s, 1);
                comentario = "M[s]:= -M[s]";
                break;
            case "AND": {
                int valor1 = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                int valor2 = Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                int valorAnd = (valor1 == 1 && valor2 == 1) ? 1 : 0;
                memoria.setValueAt(valorAnd, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "se M [s-1] = 1 e M[s] = 1  então M[s-1]:=1  senão M[s-1]:=0; s:=s - 1";
                break;
            }
            case "OR": {
                int valor1 = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                int valor2 = Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                int valorOR = (valor1 == 1 || valor2 == 1) ? 1 : 0;
                memoria.setValueAt(valorOR, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "se M[s-1] = 1  ou M[s] = 1  então M[s-1]:=1  senão M[s-1]:=0; s:=s - 1";
                break;
            }
            case "NEG":
                int negacao = 1 - Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                memoria.setValueAt(negacao, this.s, 1);
                comentario = "M[s]:=1 - M[s]";
                break;
            case "CME": {
                int valor1 = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                int valor2 = Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                int compararMenor = (valor1 < valor2) ? 1 : 0;
                memoria.setValueAt(compararMenor, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "se M[s-1] < M[s]  então M[s-1]:=1  senão M[s-1]:=0; s:=s - 1";
                break;
            }
            case "CMA": {
                int valor1 = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                int valor2 = Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                int compararMaior = (valor1 > valor2) ? 1 : 0;
                memoria.setValueAt(compararMaior, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "se M[s-1] > M[s]  então M[s-1]:=1  senão M[s-1]:=0; s:=s - 1";
                break;
            }
            case "CEQ": {
                int valor1 = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                int valor2 = Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                int compararIgual = (valor1 == valor2) ? 1 : 0;
                memoria.setValueAt(compararIgual, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "se M[s-1] = M[s]  então M[s-1]:=1  senão M[s-1]:=0; s:=s - 1";
                break;
            }
            case "CDIF": {
                int valor1 = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                int valor2 = Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                int compararDiferente = (valor1 != valor2) ? 1 : 0;
                memoria.setValueAt(compararDiferente, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "se M[s-1] ≠M[s]  então M[s-1]:=1  senão M[s-1]:=0; s:=s - 1";
                break;
            }
            case "CMEQ": {
                int valor1 = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                int valor2 = Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                int compararMenorIgual = (valor1 <= valor2) ? 1 : 0;
                memoria.setValueAt(compararMenorIgual, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "se M[s-1] ≤M[s]  então M[s-1]:=1  senão M[s-1]:=0; s:=s - 1 ";
                break;
            }
            case "CMAQ": {
                int valor1 = Integer.valueOf(memoria.getValueAt(this.s - 1, 1).toString().trim());
                int valor2 = Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                int compararMaiorIgual = (valor1 >= valor2) ? 1 : 0;
                memoria.setValueAt(compararMaiorIgual, this.s - 1, 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "se M[s-1] ≥M[s]  então M[s-1]:=1  senão M[s-1]:=0; s:=s - 1";
                break;
            }
            case "START":
                this.s = -1;
                comentario = "S:=-1";
                break;
            case "HLT":
                JOptionPane.showMessageDialog(null, "O programa Terminou!");
                return false;
            case "STR": {
                Object valorTopo = memoria.getValueAt(this.s, 1);
                memoria.setValueAt(valorTopo, Integer.valueOf(atributo1.toString().trim()), 1);
                memoria.removeRow(this.s);
                this.s--;
                comentario = "M[n]:=M[s]; s:=s-1";
                break;
            }
            case "JMP":
                this.enderecoRetorno = this.proximaInstrucao;
                this.proximaInstrucao = Integer.valueOf(atributo1.toString().trim());
                comentario = "i:= t";
                break;
            case "JMPF": {
                int valorTopo = Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                if (valorTopo == 0) {
                    this.enderecoRetorno = this.proximaInstrucao;
                    this.proximaInstrucao = Integer.valueOf(atributo1.toString().trim());
                }
                memoria.removeRow(this.s);
                this.s--;
                comentario = "seM[s] = 0 entãoi:=t senão i:=i + 1; s:=s-1";
                break;
            }
            case "NULL":
                comentario = "";
                break;
            case "RD":

                this.s++;

                String letra = "";
                do {
                    letra = JOptionPane.showInputDialog(null, "Entre com um valor");
                    if (letra == null) {
                        letra = "";
                    }

                } while (letra.isEmpty());

                memoria.addRow(new Object[]{this.s, letra});
                comentario = "S:=s + 1; M[s]:= “próximo valor de entrada”.";
                break;
            case "PRN":
                String valorImprimir = memoria.getValueAt(this.s, 1).toString().trim();
                DefaultTableModel mdlSaida = (DefaultTableModel) this.tblSaida.getModel();
                //int proximaLinha = mdlSaida.getRowCount();
                //mdlSaida.setValueAt(valorImprimir, proximaLinha, 0);
                mdlSaida.addRow(new Object[]{valorImprimir});
                memoria.removeRow(this.s);
                this.s--;
                comentario = "Imprimir M[s]; s:=s-1";
                break;
            case "ALLOC":
                for (int k = 0; k < Integer.valueOf(atributo2.toString().trim()); k++) {

                    this.s++;
                    memoria.addRow(new Object[]{this.s, null});
                    int indice = Integer.valueOf(atributo1.toString()) + k;
                    Object valorMudar = memoria.getValueAt(indice, 1);
                    //memoria.addRow(new Object[] {this.s, valorMudar});
                    memoria.setValueAt(valorMudar, this.s, 1);

                }
                comentario = "Para k:=0 até n-1 faça {s:=s + 1; M[s]:=M[m+k]}";
                break;
            case "DALLOC":
                for (int k = Integer.valueOf(atributo2.toString().trim()) - 1; k >= 0; k--) {

                    int indice = Integer.valueOf(atributo1.toString()) + k;
                    Object valorMudar = memoria.getValueAt(this.s, 1);
                    memoria.setValueAt(valorMudar, indice, 1);
                    memoria.removeRow(this.s);
                    this.s--;

                }
                comentario = "Parak:=n-1  até 0  faça {M[m+k]:=M[s]; s:=s - 1} ";
                break;
            case "CALL":
                this.s++;
                memoria.addRow(new Object[]{this.s, this.proximaInstrucao});
                //memoria.setValueAt(this.proximaInstrucao, this.s, 1);
                this.proximaInstrucao = Integer.valueOf(atributo1.toString().trim());
                comentario = "S:=s + 1; M[s]:=i+ 1; i:=t ";
                break;
            case "RETURN":
                this.proximaInstrucao = Integer.valueOf(memoria.getValueAt(this.s, 1).toString().trim());
                memoria.removeRow(this.s);
                this.s--;
                comentario = "i:=M[s]; s:=s - 1";
                break;
        }
        this.setComentario(comentario);
        this.selecionarLinhaTabela(this.tblCodigo);
        return true;
    }

    private void setComentario(String comentario) {
        DefaultTableModel codigo = (DefaultTableModel) this.tblCodigo.getModel();
        codigo.setValueAt(comentario, this.linhaComentario, 4);
    }

    private void selecionarLinhaTabela(javax.swing.JTable tabela) {

        if (tabela.getRowCount() > this.proximaInstrucao) {
            tabela.setRowSelectionInterval(this.proximaInstrucao, this.proximaInstrucao);
            GuiUtils.scrollToVisible(tabela, this.proximaInstrucao);
        }

    }

    private void limparJTable() {

        //LIMPA TBL CODIGO
        DefaultTableModel model = (DefaultTableModel) this.tblCodigo.getModel();
        model.setRowCount(0);
        this.tblCodigo.setModel(model);

        //LIMPA TBL PILHA
        model = (DefaultTableModel) this.tblPilha.getModel();
        model.setRowCount(0);
        this.tblPilha.setModel(model);

        //LIMPA TBL SAIDA
        model = (DefaultTableModel) this.tblSaida.getModel();
        model.setRowCount(0);
        this.tblSaida.setModel(model);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenu1 = new javax.swing.JPopupMenu();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblCodigo = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblPilha = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tblSaida = new javax.swing.JTable();
        jLabel3 = new javax.swing.JLabel();
        btnExecutar = new javax.swing.JButton();
        btnParar = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        radioNormal = new javax.swing.JRadioButton();
        radioPassoAPasso = new javax.swing.JRadioButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        tblCodigo.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Linha", "Instrução", "Atributo 1", "Atributo 2", "Comentario"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblCodigo.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(tblCodigo);
        tblCodigo.getColumnModel().getColumn(0).setPreferredWidth(1);
        tblCodigo.getColumnModel().getColumn(1).setPreferredWidth(10);
        tblCodigo.getColumnModel().getColumn(2).setPreferredWidth(10);
        tblCodigo.getColumnModel().getColumn(3).setPreferredWidth(10);
        tblCodigo.getColumnModel().getColumn(4).setPreferredWidth(200);

        tblPilha.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Endereço", "Valor"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane2.setViewportView(tblPilha);
        tblPilha.getColumnModel().getColumn(0).setResizable(false);
        tblPilha.getColumnModel().getColumn(1).setResizable(false);

        jLabel1.setText("Código de Máquina");

        jLabel2.setText("Máquina (Pilha)");

        tblSaida.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Dados"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane3.setViewportView(tblSaida);
        tblSaida.getColumnModel().getColumn(0).setResizable(false);

        jLabel3.setText("Saída de Dados");

        btnExecutar.setText("Executar");
        btnExecutar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExecutarActionPerformed(evt);
            }
        });

        btnParar.setText("Parar");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Modo de Execução"));
        jPanel1.setName(""); // NOI18N

        buttonGroup2.add(radioNormal);
        radioNormal.setText("Normal");

        buttonGroup2.add(radioPassoAPasso);
        radioPassoAPasso.setSelected(true);
        radioPassoAPasso.setText("Passo a Passo");
        radioPassoAPasso.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                radioPassoAPassoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(radioNormal)
                    .addComponent(radioPassoAPasso))
                .addContainerGap(43, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(radioNormal)
                .addGap(11, 11, 11)
                .addComponent(radioPassoAPasso)
                .addContainerGap())
        );

        jMenu1.setText("Arquivo");

        jMenuItem1.setText("Abrir");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Fechar");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);
        jMenu1.add(jSeparator1);

        jMenuItem3.setText("Sair");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 536, Short.MAX_VALUE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 189, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(btnParar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(btnExecutar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
                    .addGroup(layout.createSequentialGroup()
                        .addGap(86, 86, 86)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel3)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(52, 52, 52)
                                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 362, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 362, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(11, 11, 11)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnExecutar, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(btnParar, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.getAccessibleContext().setAccessibleDescription("");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed

        this.limparJTable();
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed

        this.abrirArquivo();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void radioPassoAPassoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_radioPassoAPassoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_radioPassoAPassoActionPerformed

    private void btnExecutarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExecutarActionPerformed
        this.executarCodigo();
    }//GEN-LAST:event_btnExecutarActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnExecutar;
    private javax.swing.JButton btnParar;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JRadioButton radioNormal;
    private javax.swing.JRadioButton radioPassoAPasso;
    private javax.swing.JTable tblCodigo;
    private javax.swing.JTable tblPilha;
    private javax.swing.JTable tblSaida;
    // End of variables declaration//GEN-END:variables
}
